package net.util;


public class ChemistryUtil
{
	private ChemistryUtil()
	{
		
	}
	
	/** 
	 * Returns the top level energy level of an atom that posseses <code>e</code> electrons.
	 */
	public static int getLevel(int num)
	{
		int l = 1;
		
		while (getNumber(l+1) < num)
		{
			l ++;
		}
		
		return l;
	}
	
	/** 
	 * Returns the column number of an element with zero charge and <code>n</code> electrons.
	 */
	public static int getCollumnConfig(int n)
	{
		return (n - getNumber(getLevel(n)));
	}
	
	/**
	 * Returns the number of electrons possessed by a noble gas with zero charge at energy level <code>level</code>. 
	 * In other words, <code>nobleConfig(level)</code> returns the maximum number of electrons that can fit inside 
	 * <code>level</code> without overflowing into the next level.
	 */
	public static int nobleConfig(int level)
	{
		int n = 0;
		
		for(int i = 1; i <= level; i++)
		{
			n += 2 * (i * i);
		}
		
		return n;
	}

	public static int levelConfig(int level)
	{
		return 2 * level * level;
	}
	
	/**
	 * Returns the sum of maximum number of electrons contained within energy level <code>l</code> and all preceeding energy 
	 * levels. In other words, <code>getNumber(l)</code> returns the number of electrons possessed by a nobel gas with zero 
	 * charge at energy level l.
	 */
	public static int getNumber(int level)
	{
		int n = 0;
		int sum = 0;
		while (n<level) 
		{
			sum += 2*(n*n);
			n+=1;
		}
		return sum;
	}
}
